#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <errno.h>
#include <unistd.h>
#include <string.h>

int main()
{
	int server_sockfd,client_sockfd;
	struct sockaddr_in server_addr,client_addr;
	
	if((server_sockfd = socket(AF_INET,SOCK_STREAM,0)) == -1)
	{
		perror("create socket");
		exit(EXIT_FAILURE);
	}

	server_addr.sin_family = AF_INET;
	server_addr.sin_addr.s_addr = htonl(INADDR_ANY);
	server_addr.sin_port = htons(9000);
	bzero(&(server_addr.sin_zero),8);

	if(bind(server_sockfd,(struct sockaddr *)&server_addr,sizeof(struct sockaddr)) == -1)
	{
		perror("bind");
		exit(EXIT_FAILURE);
	}

	if(listen(server_sockfd,5) == -1)
	{
		perror("listen");
		exit(EXIT_FAILURE);
	}
	
	while(1)
	{
		socklen_t size = sizeof(struct sockaddr_in);
		if((client_sockfd = accept(server_sockfd,(struct sockaddr *)&client_addr,&size)) == -1)
		{
			perror("accept");
			exit(EXIT_FAILURE);
		}
		if(send(client_sockfd,"Hello,World!",12,0) == -1)
		{
			perror("send");
			close(client_sockfd);
			exit(EXIT_FAILURE);
		}
		close(client_sockfd);
	}
}
